classdef AreaCoveredAnalyzer
%AREACOVEREDANALYZER Summary of this class goes here
%   Detailed explanation goes here

   properties
       Data = {}
       Length=0;
       DistanceCovered = 0;
       RegionLoader;
       X;
       Y;
       Z;
   end

   methods
       
       %coonstructor. Goes through and laods the regions
       %it traverses through the entire path and figures out what region
       %each time stamp is in. Once the entire path is determined, it keeps
       %track of when each region is discovered and tehn calculates a
       %distance traveled by that time
       function this = AreaCoveredAnalyzer(regionLoader, x,y,z)
           this.RegionLoader = regionLoader;
           for i=1:length(this.RegionLoader.Regions)
               this.Data{i,1} = this.RegionLoader.Regions{i}.Name;
               this.Data{i,2} = 0;
               this.Data{i,3} = 0;
               this.Data{i,4} = 0;
           end
           %this.Data{:,1} = this.RegionLoader.Regions{}.Name;
           this.Length = length(this.RegionLoader.Regions);
           
           %this.RegionLoader = regionLoader;
           this.X = x;
           this.Y = y;
           this.Z = z;
           
           current = 0;
           for i=1:length(x)
               if current >0
                   if this.RegionLoader.IsInRegion(current, x(i), y(i))
                      continue
                   end
               end
              
               current = this.RegionLoader.GetRegion2(x(i), y(i));
               if current == 0
                   continue
               end
               if this.Data{current,2} == 0
                   this.Data{current,2} = i;
               end
           end
           
           sum = 0;
           distances = ones(this.Length-1, 1);
           for i=1:length(this.X)-1
               sum = sum +         distance(this.X(i)  , ...
                                            this.X(i+1), ...
                                            this.Y(i)  , ...
                                            this.Y(i+1), ...
                                            this.Z(i)  , ...
                                            this.Z(i+1)    );
               distances(i) = sum;
           end         
           
           this.DistanceCovered = distances(length(distances));
           for i=1:this.Length
               if this.Data{i,2} ~= 0
                this.Data{i,3} = distances(this.Data{i,2});
               end
           end
           this.Data = sortcell(this.Data,2);
           this.Data = sortcell(this.Data,3);
           this.Data
           covered=0;
           for i=1:this.Length
               if this.Data{i,2} ~= 0
                   covered = covered +1;
               end
               this.Data{i,4} = covered/this.Length;
           end
       end   
       
       
       %plots the % area covered versus the distance traveled
       function Plot(this)
           x =ones(2*this.Length-1,1);
           y =ones(2*this.Length-1,1);
           
           for j=1:this.Length-1
               x(2*j-1) = this.Data{j,2};
               y(2*j-1) = this.Data{j,4};
               x(2*j) = this.Data{j,2};
               y(2*j) = this.Data{j+1,4};
           end
           %x(this.Length+1) = this.DistanceCovered;
           %y(this.Length+1) = this.Data{this.Length,4};
           line(x,y);
       end
   end
end 
